package com.xiaoxin.yixinai.companyversion;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.persistence.EntityManager;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xiaoxin.yixinai._frame.base.BaseRepository;
import com.xiaoxin.yixinai._frame.base.BaseServiceProxy;

@Service
@Transactional
public class CompanyVersionService extends BaseServiceProxy<CompanyVersion> {
	
	@Resource
    private EntityManager em;
	
	@Resource
	private CompanyVersionRepository companyVersionRepository;

	@Override
	protected BaseRepository<CompanyVersion> getBaseRepository() {
		return companyVersionRepository;
	}
	
	/**
	 * 查询某个公司配置的版本使用情况
	 * @param companyId 公司主键
	 * @return List<CompanyVersion> 公司版本集合
	 */
	public List<CompanyVersion> findByCompanyId(Integer companyId) {
		return companyVersionRepository.findByCompanyId(companyId);
	}
	
	/**
	 * 查询当前时间点，某个公司拥有的版本
	 * @param companyId 公司主键
	 * @return List<CompanyVersion> 公司拥有的版本集合
	 */
	public List<CompanyVersion> findByCompanyIdAndCurrentTime(Integer companyId) {
		Date now = new Date();
		return companyVersionRepository.findByCompanyIdAndCurrentTime(companyId, now);
	}
	
}
